package com.lagou.server;

import com.lagou.util.MySerializer;
import org.I0Itec.zkclient.ZkClient;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class BIOServer1 {

    public static void main(String[] args) throws IOException {
        //开启监听8080
        ServerSocket serverSocket = new ServerSocket(8080);

        ZkClient zkClient = new ZkClient("101.133.232.19:2181");
        //使用自定义序列化
        zkClient.setZkSerializer(new MySerializer());
        //使用临时顺序性节点注册服务端
        zkClient.createEphemeralSequential("/server-cluster/server-", "8080");

        byte[] bytes = new byte[1024];
        while (true) {
            Socket socket = serverSocket.accept();
            int length = socket.getInputStream().read(bytes);
            System.out.println(new String(bytes, 0, length));
        }
    }

}
